package hu.myai.gui.widgets.panel;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Layout;

public class PanelLayout extends Layout {
    private Panel panel;

    public PanelLayout(Panel panel) {
        this.panel = panel;
    }

    @Override
    protected Point computeSize(Composite composite, int hint, int hint2, boolean flushCache) {
        return new Point(400, 300);
    }

    @Override
    protected void layout(Composite composite, boolean flushCache) {
        Control[] controls = composite.getChildren();

        for (int i = 0; i < composite.getChildren().length; i++) {
            PanelData pd = (PanelData) controls[i].getLayoutData();

            Point pos = panel.getPosition(pd.x, pd.y);
            Point siz = panel.getSize(pd.width, pd.height);

            controls[i].setLocation(pos);
            controls[i].setSize(siz);
        }
    }
}